package cn.baiweigang.uu.strategy.future;

import cn.baiweigang.uu.model.BasisInfo;
import cn.baiweigang.uu.service.futureswap.BasisService;
import cn.baiweigang.uu.strategy.BaseStrategy;
import cn.baiweigang.uu.utils.LogUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BasisStrategy extends BaseStrategy {

    @Autowired
    private BasisService basisService;

    @Override
    public boolean init() {
        if (!super.init()) {
            return false;
        }
        strategyInfo = basisService.init(accountInfo);
        if (strategyInfo != null) {
            //TODO 策略默认配置
        }
        return strategyInfo != null;
    }

    @Override
    public void basisChange(BasisInfo basisInfo) {
        //更新基差
        strategyInfo.setLastBasis(basisInfo);

        switch (strategyInfo.getCurrentStrategyStatus()) {
            case INIT:
                LogUtil.logInfo("初始状态，先检查是否有持仓");
                basisService.checkPosition(strategyInfo);
                break;
            case WAIT_TO_OPEN:
            case EXIST_OPEN_ORDER:
            case OPEN_ORDER_DEAL:
            case WAIT_TO_CLOSE:
            case EXIST_CLOSE_ORDER:
            case CLOSE_ORDER_DEAL:
            case END:
            default:
                LogUtil.logError("策略状态不在处理范围内 " + strategyInfo.getCurrentStrategyStatus());
                break;
        }
    }


}
